package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanhua.commons.utils.UserHolder;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.model.domain.db.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author maorf
 * @version 1.0
 */
@Service
public class BlacklistService {
    @DubboReference
    BlackListApi blackListApi;
    public PageResult blacklist(Long id, Integer page, Integer pagesize) {
        //1、获取当前用户的id
        Long userId = UserHolder.getUserId();
        //2、调用API查询用户的黑名单分页列表  Ipage对象
        IPage<UserInfo> iPage = blackListApi.findByUserId(userId,page,pagesize);
        //3、对象转化，将查询的Ipage对象的内容封装到PageResult中
        PageResult pr = new PageResult(page,pagesize, (int) iPage.getTotal(),iPage.getRecords());
        //4、返回
        return pr;
    }

    //取消黑名单
    public void deleteBlackList(Long blackUserId) {
        //1、获取当前用户id
        Long userId = UserHolder.getUserId();
        //2、调用api删除
        blackListApi.delete(userId,blackUserId);
    }
}
